package com.jiyun.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiyun.model.xitong.Biaoqian;
import com.jiyun.model.xitong.Permissions;
import com.jiyun.model.xitong.Role;
import com.jiyun.model.xitong.RolePermissions;
import com.jiyun.service.IPermissionsService;
import com.jiyun.service.IRolePermissionsService;
import com.jiyun.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-23
 */
@RestController
@CrossOrigin
@RequestMapping("/role")
@Api("角色管理")
public class RoleController {
    @Autowired
    private IRoleService roleService;

    @Autowired
    private IPermissionsService permissionsService;

    @Autowired
    private IRolePermissionsService rolePermissionsService;

    @ApiOperation("查询所有角色")
    @RequestMapping("findAll")
    public List<Role> findAll() {

        return roleService.findAll();

    }

    @ApiOperation("角色添加")
    @RequestMapping("add")
    public Integer add(@RequestBody Role role) {
        return roleService.add(role);
    }

    @ApiOperation("角色修改")
    @RequestMapping("update")
    public Integer update(@RequestBody Role role) {
        return roleService.updates(role);
    }


    @ApiOperation("角色删除")
    @RequestMapping("del")
    public Integer del(Integer id) {
        return roleService.del(id);
    }


    //查询所有权限
    @ApiOperation("查询所有权限")
    @RequestMapping("findPermissions")
    public List<Permissions> findPermissions() {
        return permissionsService.findPermissions();
    }


    @ApiOperation("查询当前角色权限")
    @RequestMapping("findPermissionsByRoleId")
    public Integer[] findPermissionsByRoleId(Integer id) {
        return permissionsService.findPermissionsByRoleId(id);
    }


    @ApiOperation("分配当前权限")
    @RequestMapping("fenpei")
    public   Integer fenpei( Integer roleId, Integer[] permissionIds) {
        return  permissionsService.fenpei(roleId,permissionIds);
    }
}